﻿using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Sunny.Model.RedisCache;
using Sunny.Model.RequestParam;
using Sunny.Model.Vo;
using Sunny.Service;

namespace Sunny.Api.Controllers.Monitor
{
    [ApiController]
    public class SysUserController
    {
        private readonly UserService _userService;
        private readonly RedisService _redisService;

        public SysUserController(UserService userService,RedisService redisService)
        {
            _userService = userService;
            _redisService = redisService;
        }
        #region 获取当前在线用户

        [HttpGet("monitor/online/list")]
        public Result OnlineUser([FromQuery]UserOnlineParam param)
        {
            (List<LoginUser> users,int total) =  _userService.GetOnlineUser(param);
            return Result.Success(new
            {
                rows = users,
                total
            });
        }

        #endregion
        
        #region 强制退出当前在线用户

        [HttpDelete("monitor/online/{tokenId}")]
        public Result ForceLogout([FromRoute]string tokenId)
        {
           _redisService.DeleteKey(UserKeyPrefix.Info, tokenId);
           return Result.Success();
        }

        #endregion
    }
}